/*
 * CUnitBuilder.cpp
 *
 *  Created on: Nov 3, 2008
 *      Author: Ryan
 */

#include "CUnitBuilder.h"

#include "Unit.h"
#include "UnitAspects/AirAspect.h"
#include "UnitAspects/BuilderAspect.h"
#include "UnitAspects/BuildingAspect.h"
#include "UnitAspects/LandAspect.h"
#include "UnitAspects/ReclaimableAspect.h"
#include "UnitAspects/TransportAspect.h"
#include "UnitAspects/WaterAspect.h"
#include "UnitAspects/ResourceExtractorAspect.h"

namespace OOInterface
{

CUnitBuilder::CUnitBuilder()
{
}

CUnitBuilder::~CUnitBuilder()
{
}

UnitBuilder& CUnitBuilder::addName( std::string name )
{
	_unit->setName( name );
	return *this;
}

UnitBuilder& CUnitBuilder::addID( int id )
{
	_unit->setID( id );
	return *this;
}

UnitBuilder& CUnitBuilder::addSize( unsigned int xSize, unsigned int ySize )
{
	_unit->setSize( xSize, ySize );
	return *this;
}

UnitBuilder& CUnitBuilder::addMaxHealth( float max )
{
	_unit->setMaxHealth( max );
	return *this;
}

UnitBuilder& CUnitBuilder::addBuildTime( float time )
{
	_unit->setBuildTime( time );
	return *this;
}

UnitBuilder& CUnitBuilder::addTransportability()
{
	_unit->setTransportability( true );
	return *this;
}

UnitBuilder& CUnitBuilder::addResourceCost( const Resource& r, float amt )
{
	_unit->addResourceCost( r, amt );
	return *this;
}

UnitBuilder& CUnitBuilder::addResourceUpkeep( const Resource& r, float amt )
{
	_unit->addResourceUpkeep( r, amt );
	return *this;
}

UnitBuilder& CUnitBuilder::addResourceStorage( const Resource& r, float amt )
{
	_unit->addResourceStorage( r, amt );
	return *this;
}

UnitBuilder& CUnitBuilder::addResourceGeneration( const Resource& r, float amt )
{
	_unit->addResourceGeneration( r, amt );
	return *this;
}

UnitBuilder& CUnitBuilder::addResourceExtractorAspect( const Resource& r, float radius )
{
	ResourceExtractorAspect* a = new ResourceExtractorAspect;
	a->setRadius( radius );
	a->setResourceExtracted( r );
	_unit->addAspect( UnitAspectPtr( a ) );
	return *this;
}


UnitBuilder& CUnitBuilder::addAirAspect( float minHeight, float maxHeight )
{
	UnitAspectPtr a( new AirAspect );
	_unit->addAspect( a );
	return *this;
}

UnitBuilder& CUnitBuilder::addWaterAspect()
{
	UnitAspectPtr a( new WaterAspect );
	_unit->addAspect( a );
	return *this;
}

UnitBuilder& CUnitBuilder::addLandAspect()
{
	UnitAspectPtr a( new LandAspect );
	_unit->addAspect( a );
	return *this;
}

UnitBuilder& CUnitBuilder::addTransportAspect()
{
	UnitAspectPtr a( new TransportAspect );
	_unit->addAspect( a );
	return *this;
}

UnitBuilder& CUnitBuilder::addBuilderAspect( const ConstUnitSet& buildableUnits, float buildDistance, float buildSpeed, float repairSpeed, float captureSpeed, float reclaimSpeed )
{
	BuilderAspect* a = new BuilderAspect( buildableUnits );
	a->setBuildDistance( buildDistance );
	a->setBuildSpeed( buildSpeed );
	a->setReclaimSpeed( reclaimSpeed );
	a->setRepairSpeed( repairSpeed );

	_unit->addAspect( UnitAspectPtr( a ) );

	return *this;
}

UnitBuilder& CUnitBuilder::addBuildingAspect( float minWaterDepth, float maxWaterDepth, float maxHeightDifference )
{
	UnitAspectPtr a( new BuildingAspect( maxHeightDifference, minWaterDepth, maxWaterDepth) );
	_unit->addAspect( a );
	return *this;
}

void CUnitBuilder::reset( Unit* unit )
{
	_unit = unit;
}

Unit* CUnitBuilder::getUnit()
{
	return _unit;
}


}
